package com.wc;

import com.wc.constant.BMS;
import com.wc.domain.Book;
import com.wc.utils.RandomUtil;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;

public class Init {
    public static void main(String[] args) throws IOException {
        //初始化生成500本书并保存到文件中
        String file= BMS.DB_BOOKS;
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        for (int i = 0; i < 500; i++) {
            Book book = Book.builder()
                    .isbn(RandomUtil.genString(1,12))
                    .name(RandomUtil.genString(6,RandomUtil.genInteger(8,16)))
                    .birth(RandomUtil.genLocalDate("2000-3-3","2020-3-3"))
                    .auth(RandomUtil.genChineseName())
                    .publisher(RandomUtil.genString(6,RandomUtil.genInteger(8,14)))
                    .price(new BigDecimal(RandomUtil.genInteger(100,999)))
                    .build();
            bw.write(book.toString()+"\n");
        }
        if(bw !=null){
            bw.close();
        }
    }
}
